package test.cglibproxy;

import net.sf.cglib.proxy.Enhancer;

public class CglibProxyFactory {

    public UserServiceImpl getProxyObject(UserServiceImpl userService){
        //1.创建eh对象
        Enhancer eh=new Enhancer();
        //2.父类
        eh.setSuperclass(userService.getClass());
        //3.代理逻辑
        eh.setCallback(new UserserviceMethodIn());
        //4.创建代理对象
        UserServiceImpl userService1=(UserServiceImpl) eh.create();

        return userService1;
    }

    public static void main(String[] args) {
        CglibProxyFactory foctory=new CglibProxyFactory();
        //目标对象
        UserServiceImpl target=new UserServiceImpl();
        //代理对象
        UserServiceImpl proxyObj=foctory.getProxyObject(target);

        proxyObj.insert();
        System.out.println("---------");
        proxyObj.delete();


    }
}
